home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************/
- /* CREATES RANDOM CODE.KEY FILE FOR TEXT FILE ENCODING */
- /* range of random numbers 0 - 26 */
- /*************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <io.h>
-
- #define INVOCATION_ERROR 5
- #define FILE_ERR 10
- #define ARGCOUNT 2
- #define FILENAME argv[1]
- #define BUFFERSIZE 4096
- #define RANGE 26
- // *** ^^ range of random "shifts" ***
-
- int create_file( char *filename, long int count );
-
- void main( int argc, char **argv )
- {
- long len;
- FILE *f;
-
- if( argc != ARGCOUNT )
- {
- puts(
- "Form: fcr FILE_NAME, where FILE_NAME is the file to be encoded."
- );
-
- exit ( INVOCATION_ERROR );
- }
-
- f = fopen( FILENAME, "r" );
-
-
- len = filelength( fileno( f ) );
- printf( "\n\nCreating a CODE.KEY file more than %ld bytes long.\n", len );
- create_file( "code.key", len );
-
- fclose ( f );
-
-
- }
-
- int create_file( char *filename, long int count )
- {
- register int r;
- long n;
- FILE *fp;
-
- randomize();
-
- if( NULL == ( fp = fopen( filename, "w" ) ) )
- {
- printf( "\nCannot open file %s\n", filename );
- exit ( FILE_ERR );
- }
-
- if( setvbuf( fp, NULL, _IOFBF, BUFFERSIZE ) )
- exit( FILE_ERR );
-
- for( n = 0; n < count; n++ )
- {
- r = random( RANGE );
- fputc( r, fp );
- }
-
- fclose( fp );
-
- return ( n );
-
- }
-